# $Id$
# Maintainer: Laurent Carlier <lordheavym@gmail.com>

pkgbase=vulkan-loader-layers
pkgname=(vulkan-icd-loader vulkan-validation-layers)
_pkgname=Vulkan-LoaderAndValidationLayers
pkgver=1.0.61.1
pkgrel=1
arch=(i686 x86_64)
url="https://www.khronos.org/vulkan/"
license=('custom')
depends=()
makedepends=(git cmake python-lxml libx11 libxrandr wayland)
source=("https://github.com/KhronosGroup/${_pkgname}/archive/sdk-${pkgver}.tar.gz")
sha256sums=('47a2e56e4721ffac7df6a4e8ce2189da41331b7ed91e3879266c69302604e615')

build() {
  cd "${srcdir}/${_pkgname}-sdk-${pkgver}"

  ./update_external_sources.sh

  rm -rf build ; mkdir build ; cd build
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_INSTALL_SYSCONFDIR=/etc \
    -DCMAKE_INSTALL_DATADIR=/share \
    -DCMAKE_SKIP_RPATH=True \
    -DBUILD_TESTS=Off \
    -DBUILD_WSI_XCB_SUPPORT=On \
    -DBUILD_WSI_XLIB_SUPPORT=On \
    -DBUILD_WSI_WAYLAND_SUPPORT=On \
    -DBUILD_WSI_MIR_SUPPORT=Off \
    -DCMAKE_BUILD_TYPE=Release \
    ..
  make
}

package_vulkan-icd-loader() {
  pkgdesc="Vulkan Installable Client Driver (ICD) Loader"
  depends=(glibc)
  optdepends=('vulkan-driver: packaged vulkan driver') # vulkan-driver: vulkan-intel/vulkan-radeon/nvidia-utils/....
  cd "${srcdir}/${_pkgname}-sdk-${pkgver}/build"
  
  make DESTDIR="${pkgdir}" install
  
  rm -r ${pkgdir}/etc
  rm -r ${pkgdir}/usr/bin
  rm ${pkgdir}/usr/include/vulkan/*{.h,.hpp}
  rm ${pkgdir}/usr/lib/libVkLayer*.so

  install -m644 ../include/vulkan/vk_icd.h ${pkgdir}/usr/include/vulkan/
   
  install -dm755 ${pkgdir}/usr/share/licenses/${pkgname}
  install -m644 ../LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/
}

package_vulkan-validation-layers() {
  pkgdesc="Vulkan Software Development Kit"
  depends=(gcc-libs vulkan-icd-loader vulkan-headers libx11)
  conflicts=('vulkan-sdk')
  replaces=('vulkan-sdk')
  groups=('vulkan-devel')
  cd "${srcdir}/${_pkgname}-sdk-${pkgver}/build"
  
  make DESTDIR="${pkgdir}" install

  install -dm755 ${pkgdir}/usr/
  mv -v ${pkgdir}/etc ${pkgdir}/usr/share/
  
  # already in vulkan-headers
  rm ${pkgdir}/usr/include/vulkan/{vulkan,vk_platform}.h
  rm ${pkgdir}/usr/include/vulkan/vulkan.hpp
  # already in vulkan-icd-loader
  rm ${pkgdir}/usr/include/vulkan/vk_icd.h
  rm ${pkgdir}/usr/lib/libvulkan.so*
  rm -r ${pkgdir}/usr/lib/pkgconfig
   
  install -dm755 ${pkgdir}/usr/share/{doc,licenses}/${pkgname}
  install -m644 ../loader/LoaderAndLayerInterface.md "${pkgdir}"/usr/share/doc/${pkgname}/
  install -m644 ../LICENSE.txt "${pkgdir}"/usr/share/licenses/${pkgname}/
}
